package com.shengsiyuan.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class NioTest09 {

    public static void main(String arg[]) throws Exception{
        RandomAccessFile randomFile = new RandomAccessFile("C:\\Users\\Administrator\\IdeaProjects\\Netty-Learning\\src\\main\\java\\com\\shengsiyuan\\nio\\text\\NioTest9.txt","rw");
        FileChannel fileChannel = randomFile.getChannel();

        // 位于堆外内存
        MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE,0,5);
        mappedByteBuffer.put(0,(byte)'A');
        mappedByteBuffer.put(4,(byte)'b');

        randomFile.close();

        // 在文件管理器中打开NioTest9.txt查看
    }
}
